package com.eibus.applicationconnector.twitter;



import java.util.Properties;

import twitter4j.Twitter;
import twitter4j.TwitterFactory;
import twitter4j.conf.PropertyConfiguration;

import com.cordys.coe.util.XMLProperties;
import com.eibus.xml.nom.Node;

public class ApplicationConfiguration {

	XMLProperties xpBase;
	protected Twitter twitter;
	public ApplicationConfiguration(int iConfigNode) throws Exception {
		if (iConfigNode == 0) {
			throw new Exception("Configuration not found");
		}

		if (!Node.getName(iConfigNode).equals("configuration")) {
			throw new Exception(
					"Root-tag of the configuration should be <configuration>");
		}

		try {
			xpBase = new XMLProperties(iConfigNode);
			
			Properties properties = new Properties();
			properties.put("user", xpBase.getStringValue("user"));
			properties.put("password", xpBase.getStringValue("password"));
			properties.put("id", xpBase.getStringValue("id"));
			properties.put("oauth.accessToken", xpBase.getStringValue("oauth.accessToken"));
			properties.put("oauth.accessTokenSecret", xpBase.getStringValue("oauth.accessTokenSecret"));
			PropertyConfiguration conf1 = new PropertyConfiguration(properties);
			twitter = new TwitterFactory(conf1).getInstance();
		} catch (Exception e) {
			throw new Exception(
					"Exception while creating the configuration-object.", e);
		}

		
	}
	public Twitter getTwitter() {
		return twitter;
	}
	
	
	
}
